import java.util.*;

public class TestMain {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        Map<Integer, ArrayList<Integer>> map = new TreeMap<>();
        for(int i = 0; i < n; i++) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            ArrayList<Integer> arrayList = map.getOrDefault(a,new ArrayList<>());
            arrayList.add(b);
            map.put(a,arrayList);
        }
        int count = n/10;
        int retn = 0;
        for (Map.Entry<Integer,ArrayList<Integer>> entry: map.entrySet()) {
            ArrayList<Integer> arrayList = entry.getValue();
            Collections.sort(arrayList);
            int c = arrayList.size();
            while(c > count) {
                retn += arrayList.remove(0);
                c = arrayList.size();
            }
        }
        System.out.println(retn);
        scan.close();
    }
}
